/*
 * @lc app=leetcode.cn id=20 lang=javascript
 *
 * [20] 有效的括号
 */

// @lc code=start
/**
 * @param {string} s
 * @return {boolean}
 */
var isValid = function (s) {
  const maps = {
    "(": ')',
    "{": "}",
    "[":']'
  }
  const stack=[]
  for (let i in s) {
    if (maps[s[i]]) {
      stack.push(maps[s[i]])
    } else {
      if (stack[stack.length - 1] === s[i]) {
          stack.pop()
      } else {
         return false
       }
    }
  }
  return stack.length===0
};
// @lc code=end

